<?php
/**
 * memcached class
 */
if ( class_exists('Memcache') && isset($memcache_vars) ){
  define("_MEMCACHED", true);
}else{
  define("_MEMCACHED", false);
}

class Mcache {
  # Connection Resource
  private static $conn = null;

  public static function get($cache_name) {
    global $memcache_vars;

    if (!self::$conn) {
      self::$conn = memcache_connect($memcache_vars['host'], $memcache_vars['port']);
    }

    return memcache_get(self::$conn, $cache_name);
  }

  public static function set($cache_name, $value, $expires = 3600) {
    global $memcache_vars;

    if ($expires < 60) return;

    if (!self::$conn) {
      self::$conn = memcache_connect($memcache_vars['host'], $memcache_vars['port']);
    }

    return memcache_set(self::$conn, $cache_name, $value, true, $expires);
  }
}
?>
